<?php

namespace logsDao;

use conector\conectorMysql;
use logUtils\logUtils;

define('CAMPOS_TABLA_REGISTRO','id,tipo,texto,usuario,ip,fecha');

class logsDao extends conectorMysql{

	function insert_registro(){
		echo("INSERT REGISTRO");
	}
	
	function crear_base_datos(){
		$queryString="CREATE TABLE `registro` (
					  `id` INT(11) AUTO_INCREMENT,
					  `tipo` VARCHAR(25) COLLATE utf8_spanish_ci DEFAULT NULL,
					  `texto` VARCHAR(256) COLLATE utf8_spanish_ci DEFAULT NULL,
					  `usuario` VARCHAR(50) COLLATE utf8_spanish_ci DEFAULT NULL,
					  `ip` VARCHAR(50) COLLATE utf8_spanish_ci DEFAULT NULL,
					  `fecha` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`))
					   ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci";
		return $this->query_update($queryString);
	}
	
	function insertar_registro($tipo,$texto,$usuario){
		$queryString="INSERT INTO `backend`.`registro`(`id`,`tipo`,`texto`,`usuario`,`ip`,`fecha`) 
					  VALUES (NULL,'".$tipo."','".$texto."','".$usuario."','".$_SERVER['REMOTE_ADDR']."',CURRENT_TIMESTAMP)";
		return $this->query_update($queryString);
	}
	
	function countRegistros(){
		$queryString="SELECT COUNT(id) as total FROM registro";	
		$returnValue = $this->query_row($queryString);
		return $returnValue[0]->total;
	}
	
	function getLogsBySortLimit($sort,$limit){
		$queryString="SELECT ".CAMPOS_TABLA_REGISTRO." FROM registro ".$sort." ".$limit;
		return $this->query_row($queryString);
	}
	
	
}

?>